<script>

    $(function () {

        var form = new Vue({
            el:'#article',
            data:{
                doSubmit:false,
                doChoose:false,
                door_time:'',
                weeks:window.weeks,
            },
            mounted:function(){
                $('div.x_time').hide();
            },
            methods:{
                chooseDay:function(event){
                    var that = event.target;

                    $('div.x_time').hide();
                    $(that).parents('label:eq(0)').next('div.x_time').show();
                },
                submit:function(event){
                    if (!validator.form()){
                        return;
                    }

                    if (!confirm('系统将自动发送预约短信给客户，确认信息填写无误？')){
                        return;
                    }

                    var self = this;
                    axios.post('/ajax/order/appoint', {
                        order_id:$('[name=order_id]').val(),
                        door_time:$('[name=door_time]').val(),
                    }).then(function (response) {
                        if (response.data.code == 200) {
                            self.doSubmit = true;
                        } else {
                            alert(response.data.message || '提交失败');
                        }
                    },function (response) {
                        alert(response.data.message || '提交失败');
                    }).catch(function (err) {
                        alert('提交失败');
                    });

                }
            },
            components:{
            },
            filters:{
                localDate:function(value){
                    var weekday = this.weeks[moment.unix(value).format('E')];
                    var hour = moment.unix(value).format('H');
                    return moment.unix(value).format('M月D日('+weekday+') H:00-'+(Number(hour)+2)+':00');
                }
            }
        });

        var validator = $("#form").validate({
            rules: {
                door_time:{
                    required:true,
                },
            },
            messages: {
                door_time: {
                    required:'请先操作确认上门服务时间',
                },
            },
        });
    });
</script>